package cn.kkcxy.blog.common.config;

import cn.kkcxy.blog.common.properties.MinioProperties;
import com.alibaba.fastjson.JSON;
import io.minio.MinioClient;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @BelongsProject: kkcxy-blog
 * @BelongsPackage: cn.kkcxy.blog.commmon.config
 * @Author: kkcxy
 * @CreateTime: 2024-09-09 00:49
 * @Description: Minio 配置
 * @Version: 1.0
 */
@Slf4j
@Configuration
public class MinioConfig {

    @Resource
    private MinioProperties minioProperties;

    /**
     * 初始化 MinioClient
     */
    @Bean
    public MinioClient minioClient() {
        MinioClient client = MinioClient.builder()
                .endpoint(minioProperties.getUrl())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
        log.info("初始化 [Minio] 结束 配置为: {}", JSON.toJSONString(minioProperties));
        return client;
    }
}
